Skip to content

fix(telegram): keychain fallback + preflight SSE/user-config detection (v2.0.7)#185

Merged
auroracapital merged 4 commits intomainfrom
fix/preflight-detect-sse-router-and-userconfig
May 1, 2026
Merged

fix(telegram): keychain fallback + preflight SSE/user-config detection (v2.0.7)#185
auroracapital merged 4 commits intomainfrom
fix/preflight-detect-sse-router-and-userconfig

Conversation

@auroracapital
Copy link
Copy Markdown
Collaborator

@auroracapital auroracapital commented May 1, 2026

Summary

Two bundled fixes shipping as v2.0.7:

1. Telegram MCP server now falls back to macOS Keychain at startup

The plugin's .mcp.json injects TELEGRAM_API_ID/HASH/SESSION/PHONE via ${user_config.telegram_*} placeholders. When users configure Telegram via /ops:setup (which writes to Keychain) instead of pasting into the plugin settings UI, those placeholders resolve to empty strings and the MCP server fails to start — a working integration appeared "not configured".

Patch: telegram-server/index.js now reads:

security find-generic-password -s telegram-{api-id,api-hash,session,phone} -w

when each env var is empty. macOS-only fallback; Linux/Windows users keep using env vars or the settings UI.

Verified live: keychain probe returns FOUND for all 4 fields on the dev machine.

2. Preflight detects SSE-router + user-config.json credential sources

(Rebased onto current main from earlier branch — original commit 20821ee.) Adds two new credential scout sources to setup preflight: SSE router config and ${CLAUDE_PLUGIN_DATA_DIR}/user-config.json. New test in tests/test-preflight-sse-userconfig.sh. Updates bin/ops-setup-detect.

Test plan

  • node --check telegram-server/index.js
  • Keychain fallback returns the four fields on dev machine
  • bash -n passes on all bin/ + scripts/
  • npx prettier --check '**/*.{js,mjs,json}' — all matched files use Prettier code style
  • marketplace.json + plugin.json bumped to 2.0.7
  • CI green

Note

Medium Risk
Medium risk because it changes credential-resolution behavior (Keychain reads, SSE-router probing, and new config sources) in setup/detection paths and could misclassify channel configuration or introduce platform-specific edge cases.

Overview
Ships v2.0.7 with more robust Telegram/Slack credential detection during setup and runtime.

The Telegram MCP server now falls back to reading credentials from macOS Keychain when env vars are empty, avoiding false “not configured” starts when /ops:setup stored Telegram secrets in Keychain.

Setup preflight/detection now recognizes SSE-router–backed MCP servers (by probing ~/.claude.json mcpServers.<svc>.type=="sse" URLs) and a persisted ${CLAUDE_PLUGIN_DATA_DIR}/user-config.json fallback for Telegram, surfaces this as channels.{slack,telegram} status/source in ops-setup-detect, and adds a new bash test covering these paths. Also updates docs/agent guidance, bumps plugin/marketplace versions, and allowlists tests/ in gitleaks.

Reviewed by Cursor Bugbot for commit 6e494cc. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 1, 2026

Warning

Rate limit exceeded

@auroracapital has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 7 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 273ae636-6e7f-45d0-ba28-37b14d5b25c2

📥 Commits

Reviewing files that changed from the base of the PR and between 4bfb219 and 6e494cc.

📒 Files selected for processing (10)
  • .claude-plugin/marketplace.json
  • claude-ops/.claude-plugin/plugin.json
  • claude-ops/.gitleaks.toml
  • claude-ops/CHANGELOG.md
  • claude-ops/agents/doctor-agent.md
  • claude-ops/bin/ops-setup-detect
  • claude-ops/bin/ops-setup-preflight
  • claude-ops/skills/setup/SKILL.md
  • claude-ops/telegram-server/index.js
  • claude-ops/tests/test-preflight-sse-userconfig.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/preflight-detect-sse-router-and-userconfig

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
Review rate limit: 0/1 reviews remaining, refill in 6 minutes and 7 seconds.

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

…rces

Setup wizard previously re-prompted for Slack/Telegram even when fully
configured, because preflight only checked macOS keychain. In practice,
credentials may live in:

- ~/.claude/plugins/data/ops-ops-marketplace/user-config.json (Telegram
  api_id/api_hash/phone/session set via plugin user_config)
- SSE router on http://127.0.0.1:8090/servers/<name>/sse (auth held
  server-side; ~/.claude.json mcpServers.* shows {type:sse,url:...})

Changes:
- bin/ops-setup-preflight: probe SSE router URL and write source:sse_router
  to slack.json/telegram.txt; fall back to user-config.json for Telegram
- bin/ops-setup-detect: emit channels.<svc>.status=configured when
  preflight reports SSE router OK or user-config.json has all 4 telegram keys
- skills/setup/SKILL.md: extend Universal Credential Auto-Scan to source 11
  (user-config.json) and source 12 (SSE router probe); document detection
  short-circuit so 3a/3d skip re-setup when already wired
- agents/doctor-agent.md: cross-reference new detection sources in audit flow
- tests/test-preflight-sse-userconfig.sh: 9 cases covering SSE 200/000,
  user-config full/partial, and detect short-circuit

Reproduction (before patch):
  preferences.json → channels.slack.status=configured (source:keychain)
  preflight → slack.json {"ok":false,"reason":"no_keychain_tokens"}
  → setup wizard re-prompts Slack on every run
@auroracapital auroracapital force-pushed the fix/preflight-detect-sse-router-and-userconfig branch from 530fbed to d525b01 Compare May 1, 2026 05:58
Comment on lines +188 to +198
[ -n "$tg_phone" ] && count=$((count+1))
[ -n "$tg_session" ] && count=$((count+1))
TELEGRAM_KEYS_FOUND=$count
if [ "$count" -eq 4 ]; then
TELEGRAM_STATUS="configured"
TELEGRAM_SOURCE="user_config"
elif [ "$count" -gt 0 ]; then
TELEGRAM_STATUS="partial"
TELEGRAM_SOURCE="user_config"
fi
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.

Bug: The live-detection else block omits the keychain fallback for Telegram credentials, causing the script to incorrectly report 'unconfigured' when the preflight cache is unavailable.
Severity: MEDIUM

Suggested Fix

In the else block of the live-detection logic (lines 161-199), add a call to cred_get or a similar function to check for and retrieve Telegram credentials from the keychain. This will ensure the keychain is used as a fallback, consistent with the documented resolution order.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: claude-ops/bin/ops-setup-detect#L161-L198

Potential issue: In the live-detection logic, when the preflight cache is not available,
the `else` block (lines 161-199) checks for the SSE router and `user-config.json` but
fails to check for Telegram credentials in the keychain. This contradicts the documented
resolution order mentioned in a comment at line 134. As a result, under conditions like
a system reboot (which clears `/tmp`) or direct script execution, existing keychain
credentials will be ignored, leading to a false 'unconfigured' status and unnecessarily
re-prompting the user for credentials.

Did we get this right? 👍 / 👎 to inform future reviews.

@auroracapital auroracapital changed the title fix(preflight): detect SSE-router and user-config.json credential sources fix(telegram): keychain fallback + preflight SSE/user-config detection (v2.0.7) May 1, 2026
The plugin's .mcp.json injects TELEGRAM_API_ID/HASH/SESSION/PHONE via
${user_config.telegram_*} placeholders, which resolve to empty strings
when the user configured Telegram via /ops:setup (writes to keychain),
not the plugin settings UI. Result: a working keychain integration
appeared "not configured" because the MCP server wouldn't start.

telegram-server/index.js now falls back to:
  security find-generic-password -s telegram-{api-id,api-hash,session,phone} -w

when the env var is empty. macOS-only — Linux/Windows users continue
via env vars or settings UI.

Also bumps marketplace.json + plugin.json to 2.0.7 and adds CHANGELOG
entry covering this fix + the rebased preflight SSE/user-config
detection improvements.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@auroracapital auroracapital force-pushed the fix/preflight-detect-sse-router-and-userconfig branch from d525b01 to 2e1c865 Compare May 1, 2026 05:59
@auroracapital auroracapital merged commit 64f76df into main May 1, 2026
8 of 10 checks passed
@auroracapital auroracapital deleted the fix/preflight-detect-sse-router-and-userconfig branch May 1, 2026 06:01
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: grep -c with || echo 0 produces corrupted value
    • Replaced command substitution so grep’s exit 1 on zero matches assigns TELEGRAM_KEYS_FOUND=0 outside $(), avoiding concatenated "0\n0" and valid JSON.

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit 6e494cc. Configure here.

TELEGRAM_KEYS_FOUND=4
else
# Count keys with "found" in their value
TELEGRAM_KEYS_FOUND=$(grep -c '=found' "$PREFLIGHT/telegram.txt" 2>/dev/null || echo 0)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

grep -c with || echo 0 produces corrupted value

High Severity

When grep -c '=found' matches zero lines, it writes "0" to stdout and exits with code 1. Because || echo 0 is inside the $() command substitution, both outputs are captured, setting TELEGRAM_KEYS_FOUND to "0\n0" (two zeros separated by a newline). This corrupts the downstream [ -eq 4 ] / [ -gt 0 ] integer comparisons (bash emits "integer expression expected") and produces invalid JSON at "keys_found": $TELEGRAM_KEYS_FOUND. Moving the fallback outside the substitution (e.g. TELEGRAM_KEYS_FOUND=$(grep -c … 2>/dev/null) || TELEGRAM_KEYS_FOUND=0) avoids double capture.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6e494cc. Configure here.

auroracapital added a commit that referenced this pull request May 2, 2026
…release (#199)

The v2.0.5 → v2.0.9 patch series shipped meaningful features (multi-workspace
Slack #195, /ops:credentials audit #184, ops-ci current-state filter #196,
telegram preflight #185, userConfig schema upgrades #182). Per semver these
should have been a minor bump. This release retroactively rolls them up
into v2.1.0 with a single coherent CHANGELOG entry.

No code changes — only:
- plugin.json: 2.0.9 → 2.1.0
- CHANGELOG.md: new [2.1.0] entry consolidating Added/Fixed/Notes for the patch series
- README header + What's-new section: refer to v2.1.0
- 11 docs/*.md badges + agents-reference subtitle + migration latest-stable note: v2.0.9 → v2.1.0

Marketplace pin (.claude-plugin/marketplace.json) bumped in follow-up PR.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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