GH#3931: fix pulse-wrapper.sh BASH_SOURCE undefined in zsh#3935
GH#3931: fix pulse-wrapper.sh BASH_SOURCE undefined in zsh#3935marcusquinn merged 2 commits intomainfrom
Conversation
…wrapper.sh (GH#3931)
BASH_SOURCE is a bash-specific variable undefined in zsh. When
pulse-wrapper.sh is sourced from the MCP shell (zsh), SCRIPT_DIR
resolved to the wrong path, causing shared-constants.sh and
worker-lifecycle-common.sh to fail to source. All functions depending
on _validate_int, _sanitize_markdown, etc. then failed with
'command not found'.
Changes:
- SCRIPT_DIR: use ${BASH_SOURCE[0]:-$0} fallback for zsh compat
- Main guard: replace simple BASH_SOURCE[0]==/bin/zsh check with
_pulse_is_sourced() that uses ZSH_EVAL_CONTEXT in zsh, since
zsh sets $0 to the sourced file path (making the naive check
always true)
Closes #3931
Summary of ChangesHello, 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 addresses critical compatibility issues within Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
|
Important Review skippedAuto reviews are limited based on label configuration. 🚫 Review skipped — only excluded labels are configured. (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe PR fixes shell portability issues in pulse-wrapper.sh by introducing a fallback mechanism for BASH_SOURCE (undefined in zsh) and adding a portable source-detection helper. This ensures the script functions correctly when sourced from zsh environments without BASH_SOURCE support. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Mon Mar 9 00:16:51 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses shell portability issues when sourcing pulse-wrapper.sh in zsh. The use of ${BASH_SOURCE[0]:-$0} is a good fix for resolving the script directory, and the new _pulse_is_sourced function is a robust way to detect whether the script is being executed directly or sourced across both bash and zsh. I have one minor suggestion to simplify the zsh context check for improved readability and robustness.
Note: Security Review did not run due to the size of the PR.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.agents/scripts/pulse-wrapper.sh:
- Around line 45-49: Change the SCRIPT_DIR assignment fallback to safely handle
being sourced by replacing the final "|| exit" behavior with a sourcing-safe
pattern: after computing SCRIPT_DIR (the line that sets SCRIPT_DIR="$(cd
"$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"), use "return 2>/dev/null || exit"
so a failed directory resolution returns control when sourced and still exits
when executed; update the statement that currently uses "|| exit" to this
"return 2>/dev/null || exit" pattern to match the approach used in
config-helper.sh.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 534baf89-7e57-451b-9c62-2838bcfd2941
📒 Files selected for processing (1)
.agents/scripts/pulse-wrapper.sh
- Use 'return 2>/dev/null || exit' for SCRIPT_DIR resolution to safely handle sourced context (matches config-helper.sh pattern) - Simplify ZSH_EVAL_CONTEXT check using colon-padding idiom for cleaner single-pattern match across all list positions
🔍 Code Quality Report�[0;35m[MONITOR]�[0m Code Review Monitoring Report �[0;34m[INFO]�[0m Latest Quality Status: �[0;34m[INFO]�[0m Recent monitoring activity: 📈 Current Quality Metrics
Generated on: Mon Mar 9 00:44:39 UTC 2026 Generated by AI DevOps Framework Code Review Monitoring |
|
Both suggestions addressed in commit 96d08c8: (1) SCRIPT_DIR uses 'return 2>/dev/null || exit' for safe sourced-context handling, (2) ZSH_EVAL_CONTEXT check simplified with colon-padding idiom.



Summary
BASH_SOURCE[0]with${BASH_SOURCE[0]:-$0}for SCRIPT_DIR resolution — falls back to$0when sourced from zsh (MCP shell)BASH_SOURCE[0] == $0main guard with_pulse_is_sourced()function that usesZSH_EVAL_CONTEXTin zsh — the naive check always evaluates true in zsh because$0equals the sourced file pathProblem
When
pulse-wrapper.shis sourced from the MCP shell (zsh),BASH_SOURCE[0]is undefined, causing:SCRIPT_DIRto resolve to the wrong directoryshared-constants.shandworker-lifecycle-common.shfail to sourcecommand not founderrors for_validate_int,_sanitize_markdown, etc.Verification
bash -n pulse-wrapper.sh— syntax OKshellcheck --norc -S warning— clean (only pre-existing SC2034 warnings)_pulse_is_sourced()in all 4 scenarios: bash direct, bash sourced, zsh direct, zsh sourced — all correctCloses #3931
Summary by CodeRabbit