Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,10 @@ launchctl-ollama: ## Restart ollama launchd agent.
systemctl: systemctl-cliproxyapi systemctl-code-syncer systemctl-docker-postgres systemctl-dotfiles-updater systemctl-ollama systemctl-openclaw ## Restart all systemd user services.

.PHONY: systemctl-cliproxyapi
systemctl-cliproxyapi: ## Pull latest image and restart cliproxyapi systemd user service.
@echo "🔄 Restarting cliproxyapi..."
systemctl-cliproxyapi: ## Reload systemd units for cliproxyapi (home-manager handles restart).
@echo "🔄 Reloading cliproxyapi..."
@systemctl --user daemon-reload
@systemctl --user restart cliproxyapi.service || true
@echo "✅ cliproxyapi restarted"
@echo "✅ cliproxyapi reloaded"

.PHONY: systemctl-code-syncer
systemctl-code-syncer: ## Restart code-syncer systemd user service.
Expand Down
2 changes: 2 additions & 0 deletions config/claude/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@
"Bash(rm -rf /*:*)",
"Bash(rm -rf ~/*:*)",
"Bash(chmod -R 777:*)",
"Bash(docker system prune -a:*)",
"Bash(docker system prune -f:*)",
Comment on lines +333 to +334

@cubic-dev-ai cubic-dev-ai Bot Mar 13, 2026

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.

P1: These deny rules are bypassable with Docker's long-form flags (--all/--force), so equivalent destructive prune commands remain allowed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config/claude/settings.json, line 333:

<comment>These deny rules are bypassable with Docker's long-form flags (`--all`/`--force`), so equivalent destructive prune commands remain allowed.</comment>

<file context>
@@ -330,6 +330,8 @@
       "Bash(rm -rf /*:*)",
       "Bash(rm -rf ~/*:*)",
       "Bash(chmod -R 777:*)",
+      "Bash(docker system prune -a:*)",
+      "Bash(docker system prune -f:*)",
       "Bash(mkfs:*)",
</file context>
Suggested change
"Bash(docker system prune -a:*)",
"Bash(docker system prune -f:*)",
"Bash(docker system prune -a:*)",
"Bash(docker system prune --all:*)",
"Bash(docker system prune -f:*)",
"Bash(docker system prune --force:*)",
Fix with Cubic

"Bash(mkfs:*)",
"Bash(dd if=:*)",
"Bash(git push --force origin main:*)",
Expand Down
30 changes: 29 additions & 1 deletion config/openclaw/hydrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ STATE_DIR="${OPENCLAW_STATE_DIR:-${HOME}/.openclaw}"
CONFIG="${OPENCLAW_CONFIG_PATH:-${STATE_DIR}/openclaw.json}"
TEMPLATE="@template@"
SECRETS_DIR="${HOME}/.config/openclaw"
CLIPROXY_CONFIG="${OPENCLAW_CLIPROXY_CONFIG_PATH:-${HOME}/.cli-proxy-api/config.yaml}"
ENV_FILE="${HOME}/dotfiles/.env"

# Source .env if it exists
Expand All @@ -30,6 +31,23 @@ read_secret() {
echo ""
}

read_cliproxy_api_key_from_config() {
local config_file="$1"
[ -f "$config_file" ] || return 0

awk '
/^api-keys:/ { in_api_keys = 1; next }
in_api_keys && /^ - / {

@cubic-dev-ai cubic-dev-ai Bot Mar 13, 2026

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: This parser only handles api-keys entries written exactly as - "...", so other valid YAML styles can produce a broken apiKey value.

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

<comment>This parser only handles `api-keys` entries written exactly as `  - "..."`, so other valid YAML styles can produce a broken `apiKey` value.</comment>

<file context>
@@ -30,6 +31,23 @@ read_secret() {
+
+  awk '
+    /^api-keys:/ { in_api_keys = 1; next }
+    in_api_keys && /^  - / {
+      value = $0
+      sub(/^  - "/, "", value)
</file context>
Fix with Cubic

value = $0
sub(/^ - "/, "", value)
sub(/"$/, "", value)
print value
exit
}
in_api_keys && /^[^[:space:]]/ { exit }
' "$config_file"
}

# Load gateway token (required for both modes)
GATEWAY_TOKEN="${OPENCLAW_GATEWAY_TOKEN:-${GATEWAY_TOKEN:-$(read_secret "${SECRETS_DIR}/gateway-token")}}"

Expand All @@ -42,7 +60,17 @@ mkdir -p "$STATE_DIR"

if [ "$MODE" = "gateway" ]; then
# Gateway mode (Kyber): hydrate full template and start gateway
CLIPROXY_API_KEY="${OPENCLAW_CLIPROXY_API_KEY:-${CLIPROXY_API_KEY:-$(read_secret "${SECRETS_DIR}/cliproxy-key")}}"
cliproxy_api_key_from_env="${CLIPROXY_API_KEY:-}"
CLIPROXY_API_KEY="${OPENCLAW_CLIPROXY_API_KEY:-}"
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$(read_cliproxy_api_key_from_config "$CLIPROXY_CONFIG")"
fi
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$cliproxy_api_key_from_env"
fi
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$(read_secret "${SECRETS_DIR}/cliproxy-key")"
fi
Comment on lines +63 to +73

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 chain of if statements to determine CLIPROXY_API_KEY is functionally correct, but a bit verbose. You can make this more concise by using && short-circuiting, which improves readability without changing the logic of conditional execution.

Suggested change
cliproxy_api_key_from_env="${CLIPROXY_API_KEY:-}"
CLIPROXY_API_KEY="${OPENCLAW_CLIPROXY_API_KEY:-}"
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$(read_cliproxy_api_key_from_config "$CLIPROXY_CONFIG")"
fi
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$cliproxy_api_key_from_env"
fi
if [ -z "$CLIPROXY_API_KEY" ]; then
CLIPROXY_API_KEY="$(read_secret "${SECRETS_DIR}/cliproxy-key")"
fi
cliproxy_api_key_from_env="${CLIPROXY_API_KEY:-}"
CLIPROXY_API_KEY="${OPENCLAW_CLIPROXY_API_KEY:-}"
[ -z "$CLIPROXY_API_KEY" ] && CLIPROXY_API_KEY="$(read_cliproxy_api_key_from_config "$CLIPROXY_CONFIG")"
[ -z "$CLIPROXY_API_KEY" ] && CLIPROXY_API_KEY="$cliproxy_api_key_from_env"
[ -z "$CLIPROXY_API_KEY" ] && CLIPROXY_API_KEY="$(read_secret "${SECRETS_DIR}/cliproxy-key")"

TELEGRAM_TOKEN="${OPENCLAW_TELEGRAM_TOKEN:-${TELEGRAM_TOKEN:-$(read_secret "${SECRETS_DIR}/telegram-token")}}"
WHATSAPP_ALLOW_FROM="${OPENCLAW_WHATSAPP_ALLOW_FROM:-${WHATSAPP_ALLOW_FROM:-$(read_secret "${SECRETS_DIR}/whatsapp-allow-from")}}"
ANTHROPIC_API_KEY="${OPENCLAW_ANTHROPIC_API_KEY:-${ANTHROPIC_API_KEY:-$(read_secret "${SECRETS_DIR}/anthropic-key")}}"
Expand Down
3 changes: 2 additions & 1 deletion config/pi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"keepRecentTokens": 20000
},
"packages": [
"https://github.com/davebcn87/pi-autoresearch"
"https://github.com/davebcn87/pi-autoresearch",
"https://github.com/cagdotin/agents"
],
"skills": [],
"retry": {
Expand Down
30 changes: 5 additions & 25 deletions home-manager/services/cliproxyapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,13 @@ This directory contains the Nix-based configuration for the cliproxyapi service
~/.ccs/cliproxy/auth/ # CCS auth directory (synced from local)

S3 Storage:
├── s3://cliproxyapi/auths/ # Primary storage
└── s3://cliproxyapi/backup/auths/ # Redundant backup
└── s3://cliproxyapi/auths/ # Auth storage
```

## Data Flow

```
┌─────────────────────────────────────────────────────────┐
│ S3 (Source of Truth) │
│ ┌──────────────┐ ┌───────────────────────┐ │
│ │ auths/ │ │ backup/auths/ │ │
│ └──────┬───────┘ └───────────┬───────────┘ │
└─────────┼─────────────────────────────┼─────────────────┘
│ │
▼ hydrate.sh ▼
┌─────────────────────────────────────────────────────────┐
│ ~/.cli-proxy-api/objectstore/auths/ │
│ (local cache) │
└─────────────────────────┬───────────────────────────────┘
▼ backup.sh (on file change)
┌─────────────────────────────────────────────────────────┐
│ ~/.ccs/cliproxy/auth/ │
│ (CCS compatibility) │
└─────────────────────────────────────────────────────────┘
```
S3 auths/ -> ~/.cli-proxy-api/objectstore/auths -> ~/.ccs/cliproxy/auth
```

### Pre-start guard (service)
Expand All @@ -72,14 +54,12 @@ key error when S3 already has auths.
### Hydrate (on activation/switch)

1. Pull from S3 `auths/` → local
2. Pull from S3 `backup/auths/` → local (takes precedence, overwrites conflicts)
3. Copy local → CCS auth dir
2. Copy local → CCS auth dir

### Backup (on file change)

1. Push local → S3 `auths/`
2. Push local → S3 `backup/auths/`
3. Copy local → CCS auth dir
2. Copy local → CCS auth dir

### WatchPaths (file watchers)

Expand Down
11 changes: 8 additions & 3 deletions home-manager/services/cliproxyapi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ let
config.home.homeDirectory
or (if pkgs.stdenv.isDarwin then builtins.getEnv "HOME" else "/home/${config.home.username}");

hydrateScript = pkgs.replaceVars ./scripts/hydrate.sh {
commonScript = pkgs.replaceVars ./scripts/common.sh {
aws = "${pkgs.awscli2}/bin/aws";
};

hydrateScript = pkgs.replaceVars ./scripts/hydrate.sh {
common = commonScript;

@cubic-dev-ai cubic-dev-ai Bot Mar 13, 2026

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.

P1: start.sh still uses @aws@, but this replacement set no longer provides aws, so the generated startup script will break.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/cliproxyapi/default.nix, line 17:

<comment>`start.sh` still uses `@aws@`, but this replacement set no longer provides `aws`, so the generated startup script will break.</comment>

<file context>
@@ -9,17 +9,21 @@ let
   };
 
+  hydrateScript = pkgs.replaceVars ./scripts/hydrate.sh {
+    common = commonScript;
+  };
+
</file context>
Suggested change
common = commonScript;
aws = "${pkgs.awscli2}/bin/aws";
common = commonScript;
Fix with Cubic

};

backupScript = pkgs.replaceVars ./scripts/backup.sh {
aws = "${pkgs.awscli2}/bin/aws";
common = commonScript;
};

startScript = pkgs.replaceVars ./scripts/start.sh {
sed = "${pkgs.gnused}/bin/sed";
aws = "${pkgs.awscli2}/bin/aws";
common = commonScript;
};

# Smart wrapper that handles both NixOS and non-NixOS Linux
Expand All @@ -45,7 +50,7 @@ let
'';

wrapperScript = pkgs.replaceVars ./scripts/wrapper.sh {
aws = "${pkgs.awscli2}/bin/aws";
common = commonScript;
};

cliWrapper = pkgs.writeShellScriptBin "cliproxyapi" (builtins.readFile wrapperScript);
Expand Down
37 changes: 4 additions & 33 deletions home-manager/services/cliproxyapi/scripts/backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,13 @@
# Push auth files from local cache to S3
# shellcheck source=/dev/null
set -euo pipefail
. "@common@"

AUTH_DIR="${HOME}/.cli-proxy-api/objectstore/auths"
CCS_AUTH_DIR="${HOME}/.ccs/cliproxy/auth"
ENV_FILE="${HOME}/dotfiles/.env"
cliproxy_init_objectstore_env

if [ -f "$ENV_FILE" ]; then
set -a
. "$ENV_FILE"
set +a
fi

strip_quotes() {
local v="$1"
v="${v%\"}"
v="${v#\"}"
printf '%s' "$v"
}
ENDPOINT="$(strip_quotes "${OBJECTSTORE_ENDPOINT:-}")"
ACCESS_KEY="$(strip_quotes "${OBJECTSTORE_ACCESS_KEY:-}")"
SECRET_KEY="$(strip_quotes "${OBJECTSTORE_SECRET_KEY:-}")"

if [ -z "$ENDPOINT" ] || [ -z "$ACCESS_KEY" ] || [ -z "$SECRET_KEY" ]; then
if ! cliproxy_has_objectstore_credentials; then
echo "⚠️ Missing S3 credentials, skipping backup" >&2
exit 0
fi
Expand All @@ -35,21 +20,7 @@ fi

echo "[$(date)] Backing up auth files..." >&2

AWS_ACCESS_KEY_ID="$ACCESS_KEY" \
AWS_SECRET_ACCESS_KEY="$SECRET_KEY" \
@aws@ s3 sync \
--endpoint-url="$ENDPOINT" \
--no-progress \
"$AUTH_DIR/" \
"s3://cliproxyapi/auths/" && echo "✅ Backed up to S3 auths/" >&2

AWS_ACCESS_KEY_ID="$ACCESS_KEY" \
AWS_SECRET_ACCESS_KEY="$SECRET_KEY" \
@aws@ s3 sync \
--endpoint-url="$ENDPOINT" \
--no-progress \
"$AUTH_DIR/" \
"s3://cliproxyapi/backup/auths/" && echo "✅ Backed up to S3 backup/auths/" >&2
cliproxy_sync_auth_to_s3 "$AUTH_DIR"

# Also sync back to CCS auth dir so ccs can find the tokens
mkdir -p "$CCS_AUTH_DIR"
Expand Down
60 changes: 60 additions & 0 deletions home-manager/services/cliproxyapi/scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

cliproxy_load_env() {
local env_file="${HOME}/dotfiles/.env"
if [ -f "$env_file" ]; then
set -a
# shellcheck source=/dev/null
. "$env_file"
set +a
fi
}

cliproxy_strip_quotes() {
local value="$1"
value="${value%\"}"
value="${value#\"}"
printf '%s' "$value"
}
Comment on lines +13 to +18

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verifies current trimming behavior for double vs single quotes
v='"double-quoted"';  v="${v%\"}"; v="${v#\"}"; printf 'double => <%s>\n' "$v"
v="'single-quoted'";  v="${v%\"}"; v="${v#\"}"; printf 'single => <%s>\n' "$v"

Repository: shunkakinoki/dotfiles

Length of output: 118


🏁 Script executed:

cat -n home-manager/services/cliproxyapi/scripts/common.sh | sed -n '1,30p'

Repository: shunkakinoki/dotfiles

Length of output: 1155


🏁 Script executed:

rg "cliproxy_strip_quotes" -B 2 -A 10 home-manager/services/cliproxyapi/scripts/

Repository: shunkakinoki/dotfiles

Length of output: 2155


🏁 Script executed:

# Check for .env parsing context and how the function is called
rg "\.env|strip_quotes" home-manager/services/cliproxyapi/ -B 2 -A 2

Repository: shunkakinoki/dotfiles

Length of output: 2534


🏁 Script executed:

find home-manager/services/cliproxyapi -name "*.env*" -o -name "README*" | head -20

Repository: shunkakinoki/dotfiles

Length of output: 108


🏁 Script executed:

rg "\.env|quote" home-manager/services/cliproxyapi/README.md -B 1 -A 3

Repository: shunkakinoki/dotfiles

Length of output: 397


🏁 Script executed:

cat home-manager/services/cliproxyapi/README.md | grep -A 20 "Required in"

Repository: shunkakinoki/dotfiles

Length of output: 469


cliproxy_strip_quotes must handle both single and double-quoted .env values.

Lines 12-17 only strip double quotes ("). If .env contains single-quoted values like KEY='value', the quotes persist in the variable and break credential/endpoint usage in cliproxy_init_objectstore_env().

🔧 Suggested fix
 cliproxy_strip_quotes() {
   local value="$1"
-  value="${value%\"}"
-  value="${value#\"}"
+  case "$value" in
+    \"*\")
+      value="${value#\"}"
+      value="${value%\"}"
+      ;;
+    \'*\')
+      value="${value#\'}"
+      value="${value%\'}"
+      ;;
+  esac
   printf '%s' "$value"
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/services/cliproxyapi/scripts/common.sh` around lines 12 - 17,
The function cliproxy_strip_quotes currently only removes double quotes; update
it to handle both single and double-quoted .env values by detecting and
stripping matching leading and trailing quote characters (either ' or ") from
the input value (cliproxy_strip_quotes) before returning; ensure you only remove
a pair of matching quotes (not internal or mismatched quotes) so
cliproxy_init_objectstore_env() receives the unquoted credential/endpoint
strings.


cliproxy_init_objectstore_env() {
cliproxy_load_env
OBJECTSTORE_ENDPOINT="$(cliproxy_strip_quotes "${OBJECTSTORE_ENDPOINT:-}")"
OBJECTSTORE_BUCKET="$(cliproxy_strip_quotes "${OBJECTSTORE_BUCKET:-cliproxyapi}")"
OBJECTSTORE_ACCESS_KEY="$(cliproxy_strip_quotes "${OBJECTSTORE_ACCESS_KEY:-}")"
OBJECTSTORE_SECRET_KEY="$(cliproxy_strip_quotes "${OBJECTSTORE_SECRET_KEY:-}")"
export OBJECTSTORE_ENDPOINT OBJECTSTORE_BUCKET OBJECTSTORE_ACCESS_KEY OBJECTSTORE_SECRET_KEY
}

cliproxy_has_objectstore_credentials() {
[ -n "${OBJECTSTORE_ENDPOINT:-}" ] &&
[ -n "${OBJECTSTORE_ACCESS_KEY:-}" ] &&
[ -n "${OBJECTSTORE_SECRET_KEY:-}" ]
Comment on lines +30 to +32

@cubic-dev-ai cubic-dev-ai Bot Mar 13, 2026

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: Include OBJECTSTORE_BUCKET in the credentials check; otherwise an empty bucket passes the guard and crashes later during sync.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/cliproxyapi/scripts/common.sh, line 29:

<comment>Include `OBJECTSTORE_BUCKET` in the credentials check; otherwise an empty bucket passes the guard and crashes later during sync.</comment>

<file context>
@@ -0,0 +1,59 @@
+}
+
+cliproxy_has_objectstore_credentials() {
+  [ -n "${OBJECTSTORE_ENDPOINT:-}" ] &&
+    [ -n "${OBJECTSTORE_ACCESS_KEY:-}" ] &&
+    [ -n "${OBJECTSTORE_SECRET_KEY:-}" ]
</file context>
Suggested change
[ -n "${OBJECTSTORE_ENDPOINT:-}" ] &&
[ -n "${OBJECTSTORE_ACCESS_KEY:-}" ] &&
[ -n "${OBJECTSTORE_SECRET_KEY:-}" ]
[ -n "${OBJECTSTORE_ENDPOINT:-}" ] &&
[ -n "${OBJECTSTORE_BUCKET:-}" ] &&
[ -n "${OBJECTSTORE_ACCESS_KEY:-}" ] &&
[ -n "${OBJECTSTORE_SECRET_KEY:-}" ]
Fix with Cubic

}

cliproxy_auth_s3_uri() {
printf 's3://%s/auths/' "${OBJECTSTORE_BUCKET:?OBJECTSTORE_BUCKET is required}"
}

cliproxy_s3_sync() {
local source_path="$1"
local destination_path="$2"
AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY:?OBJECTSTORE_ACCESS_KEY is required}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY:?OBJECTSTORE_SECRET_KEY is required}" \
@aws@ s3 sync \
--endpoint-url="${OBJECTSTORE_ENDPOINT:?OBJECTSTORE_ENDPOINT is required}" \
--no-progress \
"$source_path" \
"$destination_path" || true

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 || true at the end of the aws s3 sync command will cause any sync failures to be silently ignored. While this prevents the script from exiting due to set -e, it also hides potentially important errors. It would be better to log a warning message to stderr if the sync fails. This provides visibility into failures without halting the script.

Suggested change
"$destination_path" || true
"$destination_path" || echo "⚠️ S3 sync failed. Source: '$source_path', Destination: '$destination_path'" >&2

@cubic-dev-ai cubic-dev-ai Bot Mar 13, 2026

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.

P1: Don't swallow S3 sync failures here; the backup/hydrate scripts currently treat failed transfers as success.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/cliproxyapi/scripts/common.sh, line 47:

<comment>Don't swallow S3 sync failures here; the backup/hydrate scripts currently treat failed transfers as success.</comment>

<file context>
@@ -0,0 +1,59 @@
+    --endpoint-url="${OBJECTSTORE_ENDPOINT:?OBJECTSTORE_ENDPOINT is required}" \
+    --no-progress \
+    "$source_path" \
+    "$destination_path" || true
+}
+
</file context>
Fix with Cubic

}
Comment on lines +39 to +49

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect where helper return semantics affect flow
rg -nP '\bcliproxy_s3_sync\b|\bcliproxy_sync_auth_(from|to)_s3\b' \
  home-manager/services/cliproxyapi/scripts/common.sh \
  home-manager/services/cliproxyapi/scripts/start.sh \
  home-manager/services/cliproxyapi/scripts/wrapper.sh

Repository: shunkakinoki/dotfiles

Length of output: 924


🏁 Script executed:

# Read the common.sh file to see the full context of the helper functions
head -70 home-manager/services/cliproxyapi/scripts/common.sh | tail -35

Repository: shunkakinoki/dotfiles

Length of output: 1120


🏁 Script executed:

# Read start.sh to see how these functions are called
cat home-manager/services/cliproxyapi/scripts/start.sh

Repository: shunkakinoki/dotfiles

Length of output: 5973


🏁 Script executed:

# Read wrapper.sh to see how these functions are called
cat home-manager/services/cliproxyapi/scripts/wrapper.sh

Repository: shunkakinoki/dotfiles

Length of output: 689


Remove || true from the helper function to propagate S3 sync failures to callers.

The || true on line 47 masks sync failures silently, preventing callers from detecting auth/config drift. Even though start.sh and wrapper.sh use set -euo pipefail, this cannot catch failures when the helper always returns 0. Neither caller checks the return value anyway, so failures are completely undetected. Move error handling to the caller level where decisions about retry or failure modes belong.

🔧 Suggested change
 cliproxy_s3_sync() {
   local source_path="$1"
   local destination_path="$2"
   AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY:?OBJECTSTORE_ACCESS_KEY is required}" \
     AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY:?OBJECTSTORE_SECRET_KEY is required}" \
     `@aws`@ s3 sync \
     --endpoint-url="${OBJECTSTORE_ENDPOINT:?OBJECTSTORE_ENDPOINT is required}" \
     --no-progress \
     "$source_path" \
-    "$destination_path" || true
+    "$destination_path"
 }
📝 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
cliproxy_s3_sync() {
local source_path="$1"
local destination_path="$2"
AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY:?OBJECTSTORE_ACCESS_KEY is required}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY:?OBJECTSTORE_SECRET_KEY is required}" \
@aws@ s3 sync \
--endpoint-url="${OBJECTSTORE_ENDPOINT:?OBJECTSTORE_ENDPOINT is required}" \
--no-progress \
"$source_path" \
"$destination_path" || true
}
cliproxy_s3_sync() {
local source_path="$1"
local destination_path="$2"
AWS_ACCESS_KEY_ID="${OBJECTSTORE_ACCESS_KEY:?OBJECTSTORE_ACCESS_KEY is required}" \
AWS_SECRET_ACCESS_KEY="${OBJECTSTORE_SECRET_KEY:?OBJECTSTORE_SECRET_KEY is required}" \
`@aws`@ s3 sync \
--endpoint-url="${OBJECTSTORE_ENDPOINT:?OBJECTSTORE_ENDPOINT is required}" \
--no-progress \
"$source_path" \
"$destination_path"
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@home-manager/services/cliproxyapi/scripts/common.sh` around lines 38 - 48,
The cliproxy_s3_sync helper currently swallows errors by appending "|| true";
remove that trailing "|| true" from the cliproxy_s3_sync function so the s3 sync
command returns its real exit code, allowing failures to propagate; then update
callers (e.g., start.sh and wrapper.sh) to rely on set -euo pipefail or to
explicitly check the return code of cliproxy_s3_sync and implement retry/failure
handling as needed.


cliproxy_sync_auth_from_s3() {
local auth_dir="$1"
mkdir -p "$auth_dir"
cliproxy_s3_sync "$(cliproxy_auth_s3_uri)" "$auth_dir/"
}

cliproxy_sync_auth_to_s3() {
local auth_dir="$1"
cliproxy_s3_sync "$auth_dir/" "$(cliproxy_auth_s3_uri)"
}
39 changes: 4 additions & 35 deletions home-manager/services/cliproxyapi/scripts/hydrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,18 @@
# Pull auth files from S3 to local cache
# shellcheck source=/dev/null
set -euo pipefail
. "@common@"

AUTH_DIR="${HOME}/.cli-proxy-api/objectstore/auths"
CCS_AUTH_DIR="${HOME}/.ccs/cliproxy/auth"
ENV_FILE="${HOME}/dotfiles/.env"
cliproxy_init_objectstore_env

if [ -f "$ENV_FILE" ]; then
set -a
. "$ENV_FILE"
set +a
fi

strip_quotes() {
local v="$1"
v="${v%\"}"
v="${v#\"}"
printf '%s' "$v"
}
ENDPOINT="$(strip_quotes "${OBJECTSTORE_ENDPOINT:-}")"
ACCESS_KEY="$(strip_quotes "${OBJECTSTORE_ACCESS_KEY:-}")"
SECRET_KEY="$(strip_quotes "${OBJECTSTORE_SECRET_KEY:-}")"

if [ -z "$ENDPOINT" ] || [ -z "$ACCESS_KEY" ] || [ -z "$SECRET_KEY" ]; then
if ! cliproxy_has_objectstore_credentials; then
echo "⚠️ Missing S3 credentials, skipping hydrate" >&2
exit 0
fi

mkdir -p "$AUTH_DIR"

AWS_ACCESS_KEY_ID="$ACCESS_KEY" \
AWS_SECRET_ACCESS_KEY="$SECRET_KEY" \
@aws@ s3 sync \
--endpoint-url="$ENDPOINT" \
--no-progress \
"s3://cliproxyapi/auths/" \
"$AUTH_DIR/" && echo "✅ Hydrated from S3 auths/" >&2

AWS_ACCESS_KEY_ID="$ACCESS_KEY" \
AWS_SECRET_ACCESS_KEY="$SECRET_KEY" \
@aws@ s3 sync \
--endpoint-url="$ENDPOINT" \
--no-progress \
"s3://cliproxyapi/backup/auths/" \
"$AUTH_DIR/" && echo "✅ Hydrated from S3 backup/auths/" >&2
cliproxy_sync_auth_from_s3 "$AUTH_DIR"

# Also sync to CCS auth dir so ccs can find the tokens
mkdir -p "$CCS_AUTH_DIR"
Expand Down
Loading
Loading